<template>
	<!-- 电池编辑 -->
	<div>
		<div class="edit-top">
			编辑信息
			<i class="el-icon-close" @click='cancel'></i>
		</div>
		<div class="edit-content">
			<div class="edit-title">电池信息</div>
			<div class="edit-item">
				<label>电池编码：</label><input disabled v-model="info.code" type="text" />
			</div>
			<div class="edit-item">
				<label>电池型号：</label><input v-model="info.model" type="text" />
			</div>
			<div class="edit-item">
				<label>电池类型：</label><input v-model="info.type" type="text" />
			</div>
		</div>
		<div class="edit-bottom">
			<span @click='cancel'>取消</span>
			<el-button @click='save' type="primary">保存</el-button>
		</div>
	</div>
</template>

<script>
	import Global from '@/components/Global.vue'
	export default {
		props:['id'],
		data() {
			return {
				dict: '',
				station_list:[],
				info: {
					code: '',
					model: '',
					type: '',
					currentPosition: 0,
					id:'',
					batteryCabinCode:'',
					stationId:'',

				}
			}
		},
		mounted() {
			this.get_info();
		},
		methods: {
			get_info(){
				console.log(this.id)
				var self = this;
				this.$axios.get(this.$global.serverIp + 'station/battery/detail/' + this.id)
					.then(function(res) {
						if (res != '') {
							self.info = res.data;
						}
				
					})
			},
			save() {
				if (this.info.batteryCabinCode == "") {
					this.$popup.open('电池类型不能为空');
					return;
				}
				if (this.info.positionCode == "") {
					this.$popup.open('电池型号不能为空');
					return;
				}
				var self = this;
				this.$axios.post(this.$global.serverIp + 'station/battery/save',{
					"code":self.info.code,
					"model":self.info.model,
					"type":self.info.type,
					"stationId":self.info.stationId,
					"batteryCabinCode":self.info.batteryCabinCode,
					"id":self.id
				})
					.then(function(res) {
						if (res != '') {
							self.success('编辑成功');
						}
					})
			},
			success(content) {
				var self = this;
				this.$alert(content, '提示', {
					confirmButtonText: '确定',
					callback: action => {
						self.$emit("saveEdit", 2);
					}
				});
			},
			cancel() {
				this.$emit("saveEdit", 1);
			}
		}
	}
</script>

